# here put the import lib
# @Time : 2020/8/30 21:31
# @Author : liruiyang
# @File : UserMinModel
# @Software: PyCharm
from .AdminInfoModel import AdminInfo
from ..utils.response_code import RET


class UserMin:
    def __init__(self, UserID, UserName, Email):
        self.UserID = UserID
        self.UserName = UserName
        self.Mail = Email

    @property
    def is_authenticated(self):
        return True

    @property
    def is_active(self):
        return True

    @property
    def is_anonymous(self):
        return False

    def get_id(self):
        return str(self.UserID)

    @classmethod
    def get(cls, user_id):
        result_dict = AdminInfo.get_user(user_id)
        user_info = result_dict.get("data")
        if result_dict.get("code") == '200':
            user = UserMin(
                UserID=user_info.UserID,
                UserName=user_info.UserName,
                Email=user_info.Mail,
            )
            return {"code": RET.OK, 'data': user}

        return result_dict